package com.eco.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eco.annotation.AuthToken;
import com.eco.entity.Sensor;
import com.eco.service.SensorService;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.tags.BindTag;

@RestController
/* loaded from: newfishway-1.0.0-SNAPSHOT.jar:BOOT-INF/classes/com/eco/controller/SensorController.class */
public class SensorController {
    private static final Logger log = LoggerFactory.getLogger((Class<?>) SensorController.class);

    @Autowired
    private SensorService scanService;

    
    @GetMapping({"/ir/getSensorData"})
    public JSONObject getSensorData(String startDate, String endDate, String pageNum) {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)) {
            log.error("请选择时间段");
            result.put("msg", "请选择时间段");
            result.put(BindTag.STATUS_VARIABLE_NAME, (Object) false);
            result.put("data", (Object) null);
            return result;
        }
        if (!StringUtils.isEmpty(pageNum)) {
            int total = this.scanService.countByStime(startDate, endDate);
            result.put("total", Integer.valueOf(total));
        }
        List<Sensor> sensorList = this.scanService.findByStime(startDate, endDate, pageNum, 10);
        if (CollectionUtils.isEmpty(sensorList)) {
            log.error("未查询到流速数据");
            result.put("msg", "未查询到流速数据");
            result.put(BindTag.STATUS_VARIABLE_NAME, (Object) false);
            result.put("data", (Object) null);
            return result;
        }
        JSONArray datas = new JSONArray();
        sensorList.stream().forEach(scan -> {
            JSONObject data = new JSONObject(new LinkedHashMap());
            data.put("createTime", (Object) scan.getStime());
            data.put("jksw", (Object) scan.getJksw());
            data.put("jkls", (Object) scan.getJkls());
            data.put("cksw", (Object) scan.getCksw());
            data.put("ckls", (Object) scan.getCkls());
            datas.add(data);
        });
        log.info("查询流速数据成功");
        if (!StringUtils.equals("export", pageNum)) {
            result.put("msg", "查询流速数据成功");
        }
        result.put(BindTag.STATUS_VARIABLE_NAME, (Object) true);
        result.put("data", (Object) datas);
        return result;
    }
}